<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>加密</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no,target-densitydpi = medium-dpi">
<meta name="format-detection" content="telephone=no">
<meta name="apple-touch-fullscreen" content="YES">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
</head>
<body>
<script type="text/javascript" src="/c_modules/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="/c/TZT.js"></script>
<script type="text/javascript" src="js/md5.js"></script>
<script type="text/javascript" src="js/jsencrypt.js"></script>
<script type="text/javascript">

function encryptRsa(publickkey,md5key,str){
    // Encrypt with the public key...
    var encrypt = new JSEncrypt();
    encrypt.setPublicKey(publickkey);
    var encrypted = encrypt.encrypt(str);//rsa加密
    var data = encrypt.debase64(encrypted);//把base64转成16进制
    var mac = md5('from12data' + data + md5key);
    return {
        data:data,
        mac:mac
    };
}

    
/*
*通过功能号请求公钥和MD5Key
*然后传入报文对象，返回{data,mac}
*/
var oSend = {
    action:'9999',
    ReqlinkType:2
};
$.getData({oSendData:oSend, fnSuccess:function(data){
    /*
    *请求报文，具体参数参考券商发的文档。
    *from默认12,需和券商确认。
    *调用门户地址：   https:// app端集团门户入口地址?from=xxx&data=xxx&mac=xxx
    */
    var oSend = {
        action:'5'
    }
    $.getData({oSendData:oSend, fnSuccess:function(oTime){
        var serverTime = oTime.TIME;
         var str = JSON.stringify({sn:'A01',from:'12',certType:0,certNo:'310104194811213627',custName:'测试姓名',time:serverTime});
        //处理rsa和md5key
        var PUBLICK_KEY = data.DYJR,MD5_KEY = data.HSSTRING;
        var senddata = encryptRsa(PUBLICK_KEY,MD5_KEY,str);
        //打印测试环境地址
        console.log('https://xybk.rytong.com:38021/mobile?from=12&data=' + senddata.data + '&mac=' + senddata.mac);
    }})
}});



</script>
</body>
</html>
